package com.m4f.fse.service.helper.impl;

import java.util.Set;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.m4f.fse.service.BaseService;
import com.m4f.fse.service.ObjetifyEngineService;
import com.m4f.fse.service.helper.ifc.IServiceLocator;

public class SpringServiceLocator implements IServiceLocator {
	
	private ApplicationContext ctx = null;
	
	
	public SpringServiceLocator(Set<String> configurationFiles) {
		this.ctx = new ClassPathXmlApplicationContext(configurationFiles.toArray(new String[configurationFiles.size()]));
	}
	
	@Override
	public ObjetifyEngineService getEngineService() {
		return this.getService(ObjetifyEngineService.class);
	}
	
	
	private <T extends BaseService> T getService(Class<T> clazz) {
		T bean =  this.ctx.getBean(clazz);
		return bean;
	}
}
